package com.wmyg.antifake.fabric;

import com.alibaba.fastjson.JSON;
import com.wmyg.antifake.sdk.SmartManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-11
 */
@Slf4j
@Repository
public class FabricDao {

    @Autowired
    SmartManager smartManager;

    @Async("fabricInvoke")
    public void invoke(String method, Object o) {
        String arg = JSON.toJSONString(o);
        log.info("arg is {}", arg);
        try {
            Map<String, String> map = smartManager.invoke(method, new String[]{arg});
            if ("success".equals(map.get("code"))) {
                log.info("invoke success");
//                return true;
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            log.error("invoke failed");
//            return false;
        }
//        return false;
    }

}
